# 均值方差归一化
import numpy as np

class StandardScaler:
    def __init__(self):
        self.mean = None
        self.scale = None

    def fit(self,X):
        self.mean = np.array([np.mean(X[:,i]) for i in range(X.shape[1])])
        self.scale = np.array([np.std(X[:,i]) for i in range(X.shape[1])])
        return self

    def transform(self, X):
        resX = np.empty(shape=X.shape, dtype=float)
        for col in range(X.shape[1]):
            resX[:,col] = (X[:,col] - self.mean[col]) / self.scale[col]
        return resX

